package com.yxw.springmvc.userBehavior.service.impl;

import com.yxw.springmvc.userBehavior.convert.CustPrivConvert;
import com.yxw.springmvc.userBehavior.mapper.CustPrivMapper;
import com.yxw.springmvc.userBehavior.model.CustPriv;
import com.yxw.springmvc.userBehavior.request.CustPrivaAddRequest;
import com.yxw.springmvc.userBehavior.service.CustPrivManageService;
import com.yxw.springmvc.userBehavior.util.CollectionUtils;
import com.yxw.springmvc.userBehavior.util.SequenceUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by hp on 2016/10/10.
 */
@Service
public class CustPrivManageServiceImpl implements CustPrivManageService{

    @Resource
    private SequenceUtil sequenceUtil;

    @Resource
    private CustPrivConvert custPrivConvert;

    @Resource
    private CustPrivMapper custPrivMapper;

    @Override
    public CustPriv add(CustPrivaAddRequest request) {
        if(CollectionUtils.isEmpty(request)){
            return null;
        }
        String code = sequenceUtil.getSequence();
        CustPriv custPriv = custPrivConvert.convert(request);
        custPriv.setCustPrivCode(code);
        custPrivMapper.insert(custPriv);
        return custPriv;
    }
}
